package com.fausto.learnimprint.domain

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.fausto.learnimprint.BlogApplicationTests
import com.fausto.learnimprint.core.service.impl.DiscussServiceImpl
import com.fausto.learnimprint.core.mapper.DiscussMapper
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

class DiscussTests : BlogApplicationTests() {

    @Autowired
    lateinit var discussMapper: DiscussMapper

    @Autowired
    lateinit var discussServiceImpl: DiscussServiceImpl

    /**
     *      获取最新六条评论
     */
    @Test
    fun testLatestComments() {
        discussMapper.selectList(
            QueryWrapper<com.fausto.learnimprint.core.model.entity.Discuss>().apply {
                last("limit 6")
            }
        ).forEach(::println)
    }

    /**
     *       测试获取最新评论(缓存)
     */
    @Test
    fun testLatestCache() {
        discussServiceImpl.latestComments().forEach(::println)
    }

    /**
     *      保存新评论
     */
    @Test
    fun saveDiscuss() {
        discussServiceImpl.saveDiscuss(1, "新增评论测试")
    }

    @Test
    fun delete() {
        println(discussServiceImpl.deleteDiscuss(8))
    }
}